package com.ly.drivingschool.dao;

import com.ly.drivingschool.pojo.EchartsParam;
import com.ly.drivingschool.pojo.Info;
import com.ly.drivingschool.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 数据分析dao
 */
@Component
@Mapper
public interface CountDao {
    /**
     * 汇总注册用户数据
     * @return
     */
    @Select("select count(1) from tb_user")
    int userCount();

    /**
     * 获取订单总量
     * @return
     */
    @Select("select count(1) from tb_order")
    int orderCount();

    /**
     * 获取截止某一时刻的总量
     * @param createTime
     * @return
     */
    @Select("select count(1) from tb_order where createTime <= #{createTime}")
    int timeCount(String createTime);

    /**
     * 获取指定的在职员工总量 （教练 zg001 = 01）
     * @param zg001
     * @return
     */
    @Select("select count(1) from tb_staff where zg001 = #{zg001}")
    int staffCount(String zg001);

    /**
     * 获取图表生成数据
     * 套餐信息以及对应套餐消费信息
     */
    @Select("SELECT a.setmeal_id,a.setmName,count(a.setmeal_id) setmCount FROM `tb_setmeal` a,`tb_order` b where a.setmeal_id = b.setmeal_id GROUP BY a.setmName order by a.setmeal_id")
    List<EchartsParam> getEchartsData();

    /**
     * 获取小程序 用户个人信息
     */
    @Select("SELECT a.orderTotal,a.orderPaid,b.userName,b.sex,b.phone,c.setmName,c.tc001 FROM `tb_order` a,tb_user b,tb_setmeal c where b.wxOpenId = #{open_id} and b.user_id = a.user_id and a.setmeal_id = c.setmeal_id")
    Info getInfo(String open_id);

    /**
     * 根据openId 获取教练所带学员列表
     */
    @Select("SELECT a.userName,a.phone,a.sex FROM tb_user a,tb_staff b where b.wxOpenId = #{open_id} and b.staNumber = a.staffNumber")
    List<User> getUserListByStaff(String open_id);
}
